package com.ruoyi.project.loan.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.loan.domain.UserAuth;
import com.ruoyi.project.loan.service.IUserAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户扩展信息Controller
 *
 * @author ruoyi
 * @date 2025-11-11
 */
@RestController
@RequestMapping("/loan/auth" )
public class UserAuthController extends BaseController {
    @Autowired
    private IUserAuthService userAuthService;

    /**
     * 查询用户扩展信息列表(不分页)
     */
    @PreAuthorize("@ss.hasPermi('loan:auth:list')" )
    @GetMapping("/all/list" )
    public AjaxResult allList(UserAuth userAuth) {
        List<UserAuth> list = userAuthService.selectUserAuthList(userAuth);
        return success(list);
    }

    /**
     * 查询用户扩展信息列表
     */
    @PreAuthorize("@ss.hasPermi('loan:auth:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(UserAuth userAuth) {
        startPage();
        List<UserAuth> list = userAuthService.selectUserAuthList(userAuth);
        return getDataTable(list);
    }

    /**
     * 导出用户扩展信息列表
     */
    @PreAuthorize("@ss.hasPermi('loan:auth:export')" )
    @Log(title = "用户扩展信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, UserAuth userAuth) {
        List<UserAuth> list = userAuthService.selectUserAuthList(userAuth);
        ExcelUtil<UserAuth> util = new ExcelUtil<UserAuth>(UserAuth.class);
        util.exportExcel(response, list, "用户扩展信息数据" );
    }

    /**
     * 获取用户扩展信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('loan:auth:query')" )
    @GetMapping(value = "/{authId}" )
    public AjaxResult getInfo(@PathVariable("authId" ) Long authId) {
        return success(userAuthService.selectUserAuthByAuthId(authId));
    }

    /**
     * 新增用户扩展信息
     */
    @PreAuthorize("@ss.hasPermi('loan:auth:add')" )
    @Log(title = "用户扩展信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserAuth userAuth) {
        return toAjax(userAuthService.insertUserAuth(userAuth));
    }

    /**
     * 修改用户扩展信息
     */
    @PreAuthorize("@ss.hasPermi('loan:auth:edit')" )
    @Log(title = "用户扩展信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserAuth userAuth) {
        return toAjax(userAuthService.updateUserAuth(userAuth));
    }

    /**
     * 删除用户扩展信息
     */
    @PreAuthorize("@ss.hasPermi('loan:auth:remove')" )
    @Log(title = "用户扩展信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{authIds}" )
    public AjaxResult remove(@PathVariable Long[] authIds) {
        return toAjax(userAuthService.deleteUserAuthByAuthIds(authIds));
    }
}
